package com.baseframe.user.mapper;

import com.baseframe.user.entity.SnsUserRelation;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baseframe.user.entity.vo.SnsUserRelationVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**

* @description 针对表【sns_user_relation(用户关系表)】的数据库操作Mapper
* @createDate 2023-07-05 05:57:46
* @Entity com.baseframe.user.entity.SnsUserRelation
*/
public interface SnsUserRelationMapper extends BaseMapper<SnsUserRelation> {

    @Select("select sur.user_id,sur.follow_user_id,if(sum(1) over (partition by sur.feature )>1,1,0) as is_friend from (select user_id,follow_user_id,if(user_id>follow_user_id,concat(follow_user_id,user_id),concat(user_id,follow_user_id)) as feature from sns_user_relation where is_deleted = 0 and user_id = #{userId} or follow_user_id = #{userId}) as sur;")
    List<SnsUserRelationVO> getBuddyList(@Param("userId") Long userId);
}




